<?php
use yii\helpers\Url;
use yii\Web\View;
use app\assets\AppListAsset;
AppListAsset::register($this);
$this->title = $this->context->pageTitle.Yii::$app->params['titleSuffix'];
$this->params['breadcrumbs'] = [
  [
    'label' => \Yii::t('app', 'APP Management'),
    'url' => ['app-list']
  ],
  \Yii::t('app', 'New APP')
];
$jsMsgs = $this->context->loadJsMsgs([
  'appList',
]);
$this->registerJs("VAM.setVar('LANGUAGE_JS', '".$jsMsgs."');", View::POS_HEAD);
?>
<div class="page-header">
  <h1>
    <?=\Yii::t('app', 'APP Management')?>
    <small><?=\Yii::t('app', 'New')?></small>
  </h1>
</div>
<div class="panel panel-default">
  <div class="panel-heading">
    <i class="fa fa-plus-circle"></i>
    <?=\Yii::t('app', 'New APP')?>
    <ul class="list-unstyled pull-right">
      <li>
        <a href="#">
          <i class="fa fa-chevron-up"></i>
        </a>
      </li>
    </ul>
  </div>
  <div class="panel-body">
    <div class="row">
      <div class="col-sm-8 col-sm-offset-2">
        <form class="form-horizontal" id="data-frm" method="POST" action="<?php echo Url::to(['save-app']);?>">
          <input class="hidden" type="text" name="id" value="">
          <fieldset>
            <div class="form-group">
              <label class="col-sm-2 control-label pl0" for="app_name" >
                <em>*</em>
                <?=\Yii::t('app', 'Name')?>：
              </label>
              <div class="col-sm-10">
                <input class="form-control" id="app_name" type="text" name="name" value="" placeholder="<?=\Yii::t('app', 'Name')?>">
                <div class="help-block text-error" id="app_name_err"></div>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="app_type">
                <em>*</em>
                <?=\Yii::t('app', 'APP Type')?>：
              </label>
              <div class="col-sm-10">
                <label class="radio-inline">
                  <input class='app-type' type="radio" name="type" value="1" checked> <?=\Yii::t('app', 'APP')?>
                </label>
                <label class="radio-inline">
                  <input class='app-type' type="radio" name="type" value="2"> <?=\Yii::t('app', 'WAP')?>
                </label>
                <div class="help-block"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label pl0" for="ads_selected_list">
                <em>*</em>
                <?=\Yii::t('app', 'Adspace List')?>：
              </label>				
              <div class="col-sm-10">
                <select class="form-control" id="ads_selected_list" name="adspace_ids[]" placeholder="<?=\Yii::t('app', 'Please input keywords')?>..." multiple>
                </select>
                <div class="help-block text-error" id="ads_selected_list_err"></div>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label pl0">
                <?=\Yii::t('app', 'Suggested Price')?>（CPC/￥）：
              </label>
              <label class="control-label col-md-1 pr0">
                <em>*</em>
                <?=\Yii::t('app', 'Floor Price')?>：
              </label>
              <div class="col-md-4 pl0">
                <input class="form-control" type="text" id="floor_price" value="" name="floor_price" autocomplete="off">
                <div class="help-block text-error" id="floor_price_err"></div>
              </div>
              <label class="control-label col-md-1 pr0">
                <em>*</em>
                <?=\Yii::t('app', 'Ceiling Price')?>：
              </label>
              <div class="col-md-4 pl0">
                <input class="form-control" type="text" id="ceiling_price" value="" name="ceiling_price" autocomplete="off">
                <div class="help-block text-error" id="ceiling_price_err"></div>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <label class="col-sm-2 control-label" for="app_type">
                <?=\Yii::t('app', 'Size List')?>：
              </label>
              <div class="col-sm-10">
                <p class="form-control-static" id="ads_size_list" name="ads_size_list">
                </p>
              </div>
            </div>
            <div class="form-group" id="material_protocal">
              <label class="col-sm-2 control-label" for="ads_format_list">
              <?=\Yii::t('app', 'Format')?>：
              </label>
              <div class="col-sm-7">
                <p class="form-control-static" id="ads_format_list" name="ads_format_list">
                  <span class="list-item">JPG</span>
                  <span class="list-item">, PNG</span>
                </p>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <label class="col-sm-2 control-label required" id="upload_material_label" for="upload_material">
                <em>*</em>
                <?=\Yii::t('app', 'Upload Thumbnail')?>：
              </label>
              <div class="col-sm-2 col-sm-offset-6">
                <button class="btn btn-info" id="upload-material" type="button">
                  <i class="fa fa-upload"></i>
                  <?=\Yii::t('app', 'Upload')?>
                </button>
              </div>
              <div class="col-sm-12 mt10 text-center">
                <div class="creative-preview-wrap">
                </div>
                <img class="img-thumbnail creative_material_default" id="creative_material_default" data-src="holder.js/310x260/text:<?=\Yii::t('app', 'Not upload')?>" alt="<?=\Yii::t('app', 'Not upload')?>">
                <input id="upload_material" data-err="upload_material_err" type="hidden" value="">
                <div class="help-block text-error" id="upload_material_err"></div>
              </div>
            </div>
          </fieldset>
          <fieldset>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-10">
                <div class="btn-form-group pull-right">
                  <button type="submit" class="btn btn-primary" data-loading-text="<i class='fa fa-spinner fa-spin'></i> <?=\Yii::t('common', 'Saving')?>..."><?=\Yii::t('common', 'Save')?></button>
                  <a href="<?php echo Url::to(['app/app-list']); ?>" class="btn btn-default"><?=\Yii::t('common', 'Back')?></a>
                </div>
              </div>
            </div>
          </fieldset>
        </form>
      </div>
    </div>
  </div>
</div>
<div class="modal fade" id="upload-material-modal">
  <div class="modal-dialog modal-lg">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        <h4 class="modal-title"><?=\Yii::t('app', 'Upload Thumbnail')?></h4>
      </div>
      <div class="modal-body">
        <div class="portlet-content">
          <span class="btn btn-success btn-sm fileinput-button">
            <i class="fa fa-plus"></i>
            <span><?=\Yii::t('app', 'File')?></span>
            <input id="creative-id" type="hidden" name="creative_id" value="${id}" >
            <!-- The file input field used as target for the file upload widget -->
            <input type="file" multiple="" name="files[]" id="fileupload">
          </span>
          <br>
          <br>
          <!-- The global progress bar -->
          <div class="progress" id="progress">
              <div aria-valuemax="100" aria-valuemin="0" class="progress-bar progress-bar-success progress-bar-striped">0%</div>
          </div>
          <!-- The container for the uploaded files -->
          <div class="files" id="files">
            <table class="table table-striped table-bordered">
              <thead>
                <tr>
                  <th>ID</th>
                  <th><?=\Yii::t('app', 'File Name')?></th>
                  <th><?=\Yii::t('app', 'File Size')?>(KB)</th>
                  <th><?=\Yii::t('app', 'Upload Time')?></th>
                  <th><?=\Yii::t('app', 'Info')?></th>
                  <th><?=\Yii::t('app', 'Uploader')?></th>
                </tr>
              </thead>
              <tbody></tbody>
              </table>
            </div>
        </div>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal"><?=\Yii::t('common', 'Close')?></button>
        <button type="button" class="btn btn-primary" id="upload-confirm-operate" data-material-id=""><?=\Yii::t('common', 'Sure')?></button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<?php
  //$adsListUrl = Yii::getAlias('@web') . '/response/app/adsToAppList.php';
  $adsListUrl = Url::to(['get-unbind-adspace']);
  //$adsSizeAndFormatList = Yii::getAlias('@web') . '/response/app/adsSizeAndFormat.php';
  $adsSizeAndFormatList = Url::to(['get-adspace-size-and-formats']);
  $uploadMaterialUrl =  Url::to(['upload-ads-pic']);
  //$uploadMaterialUrl = Yii::getAlias('@web') . '/response/app/uploadAdsThumbnail.php';
  $this->registerJs("VAM.setVar('ADS_TO_APP_LIST','$adsListUrl');", View::POS_END);
  $this->registerJs("VAM.setVar('ADS_SIZE_FORMAT_LIST','$adsSizeAndFormatList');", View::POS_END);
  $this->registerJs("VAM.setVar('UPLOAD_MATERIAL_URL','$uploadMaterialUrl');", View::POS_HEAD);
?>
<script type="text/javascript" >
  requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/site.js"], function(common) {
    requirejs(["<?= Yii::getAlias('@web/').Yii::$app->params['envDir'];?>/js/app/newApp.js"]);
  });
</script>
